﻿@{
    ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>

<p>Bitcoin Tracker is an web client for tracking and managing bitcoins transactions done on <a href="https://www.bitstamp.net/" target="_blank">BITSTAMP</a></p>

<p>
    The source code of this project is available at: <a href="https://bitcointracker.codeplex.com/">https://bitcointracker.codeplex.com/</a>
</p>
<p>The project consists of two parts:</p>
<ul>
    <li>The first part consists of using the web socket provided by Bitstamp in order to receive information
    about the current trades. The information about how to connect to the web socket is available here: <a href="https://www.bitstamp.net/websocket/">https://www.bitstamp.net/websocket/ </a>
    </li>
    <li>
        The second part consists of creating an web socket between the client and a server in order to make
        the total sum and amount of selected transactions. In order to implement the web socket in a ASP.NET MVC 5 project
        I used the <a href="http://signalr.net/">SignalR</a> library that is provided by microsoft.</li>
</ul>

<h4>First part - Connecting thought a web socket to Bitstamp </h4>
<p>
    Bitstamp uses Pusher for real time websocket. Pusher is a simple hosted API for quickly, easily and securely adding realtime bi-directional functionality via WebSockets to web and mobile apps, or any other Internet connected device.
    Using the javascript client offered by Pusher a user can create a Pusher object providing the unique pusher key to identify the specific Pusher client. This object can be used to subscribe to different channels that are offered by the Bitstamp.
    I subscribed to the 'live_trades' channel to the event 'trade'. The Pusher key for Bitstamp is 'de504dc5763aeef9ff52'.

    When a new transaction if available the web socket streams the JSON dictionary:
    <ul>
        <li> id - trade unique ID </li>
        <li> amount - trade amount </li>
        <li> price - trade price </li>
    </ul>
</p>

<h4>Second part - creating server and client that accepts and connects to a web socket </h4>
<p>
    In order to achive this I used the SignalR library that was created by Microsoft. I made the decision to use it
    because being developed by the ASP.NET Team provided the best integration with the ASP.NET platform. 
</p>
<p>
    By default it uses web sockets in order to establish a connection between the server and a client 
    but in the case that the browser does not support web sockets it has the capability to fallback 
    to comet and other technologies that are supported by the browser. This means that the web applications
    created using the SignalR library will work even on old (or not so old :) ) browsers.
</p>

<p>
    The client (the right side of the webpage) connects to the server using a web socket. It's purpuse is to send
    selected trades to the server and get the total amount and price of the selected transactions. This can be used
    in order to track different transactions.
</p>
<p>
    SignalR allows the server and client to expose different methods for communication purposes.
    The server exposes the following methods:
</p>
<ul>
    <li>
        ClearContentCurrentClient()
    </li>
    <li>
        AddToAvarage(int id, double amount, double price)
    </li>
    <li>
        RemoveFromAvarage(int id)
    </li>
</ul>
<p>
    The client exposes the following methods:
</p>
<ul>
    <li>
        updateTotalAmount = function (message, totalAmount, totalPrice)
    </li>
    <li>
        updateMessage = function (message)
    </li>
</ul>